package com.youan.serve.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youan.pangu.base.exception.BusinessException;
import com.youan.serve.dao.domain.SysArgu;
import com.youan.serve.dao.idao.SysArguMapper;
import com.youan.serve.service.ISysarguService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author auto_code
 * @since 2020-03-04
 */
@Service
public class SysArguServiceImpl extends ServiceImpl<SysArguMapper, SysArgu> implements ISysarguService {

    @Override
    public boolean judgeArgu(SysArgu sysArgu) throws Exception{
        if (sysArgu == null) {
            throw new BusinessException("对象不存在！");
        }
        if (sysArgu.getArguName() == null || sysArgu.getArguName().equals("")) {
            throw new BusinessException("参数名称不存在！");
        }
        if (sysArgu.getArguType() == null || sysArgu.getArguType().equals("")) {
            throw new BusinessException("参数类型不存在！");
        }
        if (sysArgu.getArguValue() == null || sysArgu.getArguValue().equals("")) {
            throw new BusinessException("参数值不存在！");
        }
        String arguId = "";
        if(sysArgu.getArguId()!=null){
            arguId = sysArgu.getArguId();
        }
        List<SysArgu> sysArguList = this.list(new LambdaQueryWrapper<SysArgu>()
                .eq(SysArgu::getArguName, sysArgu.getArguName())
                .ne(SysArgu::getArguId, sysArgu.getArguId())
        );
        if(sysArguList!=null && sysArguList.size()>0){
            throw new BusinessException("存在重复名称的参数！");
        }
        return true;
    }
}
